import os

from django.apps import AppConfig


class LicenseConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'license'

    def ready(self):
        # 此时模型类加载好了, 但是数据库连接还未创建
        if os.environ.get('DJANGO_SETTINGS_MODULE') == 'project.settings.staging':
            from license.models.device import Device
            from license.models.license import Serial
            from license.models.account import Account, Reseller
            Reseller._meta.managed = True
            Device._meta.managed = True
            Account._meta.managed = True
            for i in range(128):
                Serial.sharding_get(i)._meta.managed = True
